﻿<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="jQueryTest_Yifeng.aspx.vb" Inherits="WebPhonebook.jQueryTest_Yifeng" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
     <script src ="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
</head>
<body>
    <form id="form1" runat="server">
    <div id="demo">
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <br />
        <br />
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
        <br />
        <br />
        <asp:CheckBox ID="CheckBox1" runat="server" />
        <br />
        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
            <asp:ListItem Value="first"></asp:ListItem>
            <asp:ListItem Value="second"></asp:ListItem>
            <asp:ListItem Value="third"></asp:ListItem>
        </asp:DropDownList>

        <br />
        <br />

        <asp:HiddenField ID="ValueChanged" runat="server" />
        <%--<asp:HiddenField ID="NoPostBack" runat="server" />--%>
        
        <%--<input id="ValueChanged" type="hidden" />--%>
        <input id="NoPostBack" type="hidden" />
        <br />
        <a id="ref" href="http://www.google.com" onclick="document.getElementById('NoPostBack').value = 'True';">Google</a>
       <%-- <a id="ref" href="http://www.google.com" onclick="NoPostBack=true;">Google</a>--%>
        
    </div>
    </form>

   
    <script type="text/javascript">

        //var ValueChanged;
        //var NoPostBack;

        $("input:text").each(function () {

            $(this).change(function () {
                document.getElementById('ValueChanged').value = "True";
                document.getElementById('NoPostBack').value = "True";
                //ValueChanged = true;
                //NoPostBack = true;
            });
        });

        $("input:checkbox").each(function () {

            $(this).change(function () {

                document.getElementById('ValueChanged').value = "True";
                document.getElementById('NoPostBack').value = "True";
                //ValueChanged = true;
                //NoPostBack = true;
            });
        });

        $("select").each(function () {

            $(this).change(function () {

                document.getElementById('ValueChanged').value = "True";
                document.getElementById('NoPostBack').value = "False";
                //ValueChanged = true;
                //NoPostBack = false;
            });
        });    
    </script>

    <script type="text/javascript">

        
        window.onbeforeunload = confirmLeave;
        

        function confirmLeave() {
            if (document.getElementById('ValueChanged').value == "True" && document.getElementById('NoPostBack').value == "True") {
                document.getElementById('ValueChanged').value = "False";
                document.getElementById('NoPostBack').value="False";
                return "You have attempted to leave this page without saving!";}

//            if (ValueChanged && NoPostBack) {
//                ValueChanged = false;
//                NoPostBack = false;
//                return "You have attempted to leave this page without saving!";
//              }
            
        }
    </script>

</body>
</html>
